package com.document.finance.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.document.finance.entity.clew;
import com.document.finance.service.ClewService;
import com.tencent.wework.Finance;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

@RestController
@RequestMapping("/democontroller")
@Tag(name = "测试接口")
public class DemoController {
    @Autowired
    private ClewService ClewService;

    @Operation(summary = "Consul检测服务")
    @RequestMapping(value = "/Health", method = RequestMethod.GET)
    public List<clew> Health() {
        return ClewService.selectAll();
    }

    @Operation(summary = "会话测试")
    @RequestMapping(value = "/Demo", method = RequestMethod.GET)
    public String Demo() {
        long ret = 0;
        long sdk = Finance.NewSdk();
        ret = Finance.Init(sdk, "wx60fb60c92a367e5d", "lm2utAILswIc60yHGwlC4aZchT2TvoY8uSvHteh5uTY");
        if (ret != 0) {
            Finance.DestroySdk(sdk);
            System.out.println("init sdk err ret " + ret);
        } else {
            int seq =0;
            int limit = 50;
            int timeout =500;
            //每次使用GetChatData拉取存档前需要调用NewSlice获取一个slice，在使用完slice中数据后，还需要调用FreeSlice释放。
            long slice = Finance.NewSlice();
            ret = Finance.GetChatData(sdk, seq, limit,"","", timeout, slice);
            if (ret != 0) {
                System.out.println("getchatdata ret " + ret);
                Finance.FreeSlice(slice);
            }
            System.out.println("getchatdata :" + Finance.GetContentFromSlice(slice));
            Finance.FreeSlice(slice);
        }
        return "0";
    }
}
